{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "689301b1-7deb-4343-ac99-863a8609d989",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fc40b9c9-c9f1-469b-bd2f-a80eb7e3e53b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "# ..................................................\n",
    "import pandas      # Pandas 2.0.3\n",
    "import sqlalchemy  # SQLAlchemy 2.0.36\n",
    "# ..................................................\n",
    "from GF_PY3_CLASS import Python_3_Finance_Data_Conv_Daily_to_Weekly\n",
    "from GF_PY3_CLASS import Python_3_Finance_DataFrame_Preprocessing\n",
    "from GF_PY3_CLASS import Python_3_Finance_Entanglement_Theory\n",
    "from GF_PY3_CLASS import Python_3_Finance_Indicator_EMA\n",
    "from GF_PY3_CLASS import Python_3_Finance_Indicator_KDJ\n",
    "from GF_PY3_CLASS import Python_3_Finance_Indicator_MACD\n",
    "from GF_PY3_CLASS import Python_3_Finance_Indicator_SMA\n",
    "from GF_PY3_CLASS import Python_3_SQLAlchemy_2_SQLite_3\n",
    "from GF_PY3_CLASS import Python_3_Text_Progress_Bar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1e83bbe9-d065-4111-85a9-f6944e9de370",
   "metadata": {},
   "outputs": [],
   "source": [
    "OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly = Python_3_Finance_Data_Conv_Daily_to_Weekly.Python_3_Finance_Data_Conv_Daily_to_Weekly()\n",
    "OBJECT_Python_3_Finance_DataFrame_Preprocessing   = Python_3_Finance_DataFrame_Preprocessing.Python_3_Finance_DataFrame_Preprocessing()\n",
    "OBJECT_Python_3_Finance_Entanglement_Theory       = Python_3_Finance_Entanglement_Theory.Python_3_Finance_Entanglement_Theory()\n",
    "OBJECT_Python_3_Finance_Indicator_EMA12           = Python_3_Finance_Indicator_EMA.Python_3_Finance_Indicator_EMA()\n",
    "OBJECT_Python_3_Finance_Indicator_EMA26           = Python_3_Finance_Indicator_EMA.Python_3_Finance_Indicator_EMA()\n",
    "OBJECT_Python_3_Finance_Indicator_KDJ             = Python_3_Finance_Indicator_KDJ.Python_3_Finance_Indicator_KDJ()\n",
    "OBJECT_Python_3_Finance_Indicator_MACD            = Python_3_Finance_Indicator_MACD.Python_3_Finance_Indicator_MACD()\n",
    "OBJECT_Python_3_Finance_Indicator_SMA5            = Python_3_Finance_Indicator_SMA.Python_3_Finance_Indicator_SMA()\n",
    "OBJECT_Python_3_Finance_Indicator_SMA10           = Python_3_Finance_Indicator_SMA.Python_3_Finance_Indicator_SMA()\n",
    "OBJECT_Python_3_SQLAlchemy_2_SQLite_3             = Python_3_SQLAlchemy_2_SQLite_3.Python_3_SQLAlchemy_2_SQLite_3()\n",
    "OBJECT_Python_3_Text_Progress_Bar                 = Python_3_Text_Progress_Bar.Python_3_Text_Progress_Bar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bbd99af0-7e92-400e-903a-e58c2646ea31",
   "metadata": {},
   "outputs": [],
   "source": [
    "OBJECT_Python_3_SQLAlchemy_2_SQLite_3.DB_PATH    = r\"D:\\TEMP\\TEMP_FINANCE_20250808\\GF_SQLITE3_FINANCE.db\"\n",
    "DB_TABLE_DAILY_DATA                              = r\"tushare_api_cache_en_us\"\n",
    "DB_TABLE_DAILY_DATA_INDICATOR                    = f\"tushare_api_cache_en_us_indicator\"\n",
    "DB_TABLE_WEEKLY_DATA                             = r\"stocks_en_us_weekly_data\"\n",
    "STOCKS_ADJUSTED                                  = r\"不复权\"\n",
    "SQL_STATMENT_STOCKS_DAILY_ALL                    = f\"SELECT * FROM {DB_TABLE_DAILY_DATA} WHERE memo REGEXP '.*股票.*|.*日数据.*|.*{STOCKS_ADJUSTED}.*';\"\n",
    "SQL_STATMENT_STOCKS_DAILY_ONLY_WITHOUT_INDICATOR = f\"SELECT * FROM {DB_TABLE_DAILY_DATA} WHERE memo REGEXP '.*股票.*|.*日数据.*|.*{STOCKS_ADJUSTED}.*' AND id NOT IN (SELECT id FROM {DB_TABLE_DAILY_DATA_INDICATOR});\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "77d2f111-bec2-4407-877f-4c08b8ead0b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>unique</th>\n",
       "      <th>code</th>\n",
       "      <th>time</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>chg_pct</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>memo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>2025-04-01</td>\n",
       "      <td>11.27</td>\n",
       "      <td>11.30</td>\n",
       "      <td>11.22</td>\n",
       "      <td>11.27</td>\n",
       "      <td>11.26</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.0888</td>\n",
       "      <td>681470.42</td>\n",
       "      <td>767424.131</td>\n",
       "      <td>股票/日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>2025-04-01</td>\n",
       "      <td>7.07</td>\n",
       "      <td>7.21</td>\n",
       "      <td>7.04</td>\n",
       "      <td>7.11</td>\n",
       "      <td>7.05</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.8511</td>\n",
       "      <td>709650.66</td>\n",
       "      <td>506589.289</td>\n",
       "      <td>股票/日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>None</td>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>2025-04-01</td>\n",
       "      <td>9.89</td>\n",
       "      <td>10.30</td>\n",
       "      <td>9.85</td>\n",
       "      <td>10.10</td>\n",
       "      <td>9.74</td>\n",
       "      <td>0.36</td>\n",
       "      <td>3.6961</td>\n",
       "      <td>67041.00</td>\n",
       "      <td>67550.741</td>\n",
       "      <td>股票/日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>None</td>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>2025-04-01</td>\n",
       "      <td>7.39</td>\n",
       "      <td>7.50</td>\n",
       "      <td>7.20</td>\n",
       "      <td>7.23</td>\n",
       "      <td>7.29</td>\n",
       "      <td>-0.06</td>\n",
       "      <td>-0.8230</td>\n",
       "      <td>753957.97</td>\n",
       "      <td>551379.613</td>\n",
       "      <td>股票/日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>None</td>\n",
       "      <td>000007.SZ</td>\n",
       "      <td>2025-04-01</td>\n",
       "      <td>6.08</td>\n",
       "      <td>6.24</td>\n",
       "      <td>6.08</td>\n",
       "      <td>6.13</td>\n",
       "      <td>6.09</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.6568</td>\n",
       "      <td>35371.00</td>\n",
       "      <td>21768.439</td>\n",
       "      <td>股票/日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063607</th>\n",
       "      <td>1063608</td>\n",
       "      <td>None</td>\n",
       "      <td>920978.BJ</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>36.68</td>\n",
       "      <td>41.63</td>\n",
       "      <td>36.55</td>\n",
       "      <td>41.30</td>\n",
       "      <td>36.80</td>\n",
       "      <td>4.50</td>\n",
       "      <td>12.2283</td>\n",
       "      <td>68911.42</td>\n",
       "      <td>269265.915</td>\n",
       "      <td>日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063608</th>\n",
       "      <td>1063609</td>\n",
       "      <td>None</td>\n",
       "      <td>920981.BJ</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>35.08</td>\n",
       "      <td>36.76</td>\n",
       "      <td>35.08</td>\n",
       "      <td>36.66</td>\n",
       "      <td>35.18</td>\n",
       "      <td>1.48</td>\n",
       "      <td>4.2069</td>\n",
       "      <td>15609.99</td>\n",
       "      <td>56280.395</td>\n",
       "      <td>日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063609</th>\n",
       "      <td>1063610</td>\n",
       "      <td>None</td>\n",
       "      <td>920982.BJ</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>244.12</td>\n",
       "      <td>268.00</td>\n",
       "      <td>238.01</td>\n",
       "      <td>264.19</td>\n",
       "      <td>245.86</td>\n",
       "      <td>18.33</td>\n",
       "      <td>7.4555</td>\n",
       "      <td>25679.01</td>\n",
       "      <td>643499.455</td>\n",
       "      <td>日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063610</th>\n",
       "      <td>1063611</td>\n",
       "      <td>None</td>\n",
       "      <td>920985.BJ</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>8.80</td>\n",
       "      <td>9.65</td>\n",
       "      <td>8.45</td>\n",
       "      <td>9.42</td>\n",
       "      <td>8.90</td>\n",
       "      <td>0.52</td>\n",
       "      <td>5.8427</td>\n",
       "      <td>134868.64</td>\n",
       "      <td>121428.040</td>\n",
       "      <td>日数据/不复权</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063611</th>\n",
       "      <td>1063612</td>\n",
       "      <td>None</td>\n",
       "      <td>920992.BJ</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>21.48</td>\n",
       "      <td>22.46</td>\n",
       "      <td>21.00</td>\n",
       "      <td>22.46</td>\n",
       "      <td>21.53</td>\n",
       "      <td>0.93</td>\n",
       "      <td>4.3196</td>\n",
       "      <td>24675.37</td>\n",
       "      <td>53815.799</td>\n",
       "      <td>日数据/不复权</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1063612 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              id unique       code        time    open    high     low  \\\n",
       "0              1   None  000001.SZ  2025-04-01   11.27   11.30   11.22   \n",
       "1              2   None  000002.SZ  2025-04-01    7.07    7.21    7.04   \n",
       "2              3   None  000004.SZ  2025-04-01    9.89   10.30    9.85   \n",
       "3              4   None  000006.SZ  2025-04-01    7.39    7.50    7.20   \n",
       "4              5   None  000007.SZ  2025-04-01    6.08    6.24    6.08   \n",
       "...          ...    ...        ...         ...     ...     ...     ...   \n",
       "1063607  1063608   None  920978.BJ  2025-10-29   36.68   41.63   36.55   \n",
       "1063608  1063609   None  920981.BJ  2025-10-29   35.08   36.76   35.08   \n",
       "1063609  1063610   None  920982.BJ  2025-10-29  244.12  268.00  238.01   \n",
       "1063610  1063611   None  920985.BJ  2025-10-29    8.80    9.65    8.45   \n",
       "1063611  1063612   None  920992.BJ  2025-10-29   21.48   22.46   21.00   \n",
       "\n",
       "          close  pre_close  change  chg_pct     volume      amount        memo  \n",
       "0         11.27      11.26    0.01   0.0888  681470.42  767424.131  股票/日数据/不复权  \n",
       "1          7.11       7.05    0.06   0.8511  709650.66  506589.289  股票/日数据/不复权  \n",
       "2         10.10       9.74    0.36   3.6961   67041.00   67550.741  股票/日数据/不复权  \n",
       "3          7.23       7.29   -0.06  -0.8230  753957.97  551379.613  股票/日数据/不复权  \n",
       "4          6.13       6.09    0.04   0.6568   35371.00   21768.439  股票/日数据/不复权  \n",
       "...         ...        ...     ...      ...        ...         ...         ...  \n",
       "1063607   41.30      36.80    4.50  12.2283   68911.42  269265.915     日数据/不复权  \n",
       "1063608   36.66      35.18    1.48   4.2069   15609.99   56280.395     日数据/不复权  \n",
       "1063609  264.19     245.86   18.33   7.4555   25679.01  643499.455     日数据/不复权  \n",
       "1063610    9.42       8.90    0.52   5.8427  134868.64  121428.040     日数据/不复权  \n",
       "1063611   22.46      21.53    0.93   4.3196   24675.37   53815.799     日数据/不复权  \n",
       "\n",
       "[1063612 rows x 14 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = OBJECT_Python_3_SQLAlchemy_2_SQLite_3.Query(SQL_STATMENT_STOCKS_DAILY_ALL)\n",
    "df = df.rename(columns = {\"ts_code\": \"code\", \"pct_chg\": \"chg_pct\", \"vol\": \"volume\"})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e259117a-1d0f-4acd-b771-cd2e7b7b6bcd",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = OBJECT_Python_3_Finance_DataFrame_Preprocessing.Before_Calculating_Daily_Indicators(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4edf8b0c-46a3-4d9f-b467-9f0e8ca49d39",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[DEBUG] PROCESSING: [====================>] Pct: 1.00 | 1063612/1063612"
     ]
    }
   ],
   "source": [
    "JSON_Records_Stocks_Daily_Indicator:list = []\n",
    "# ..............................................\n",
    "Total = df[\"id\"].count()\n",
    "Count = 1\n",
    "# ..............................................\n",
    "for Idx, Row in df.iterrows():\n",
    "    ID             = Row[\"id\"]\n",
    "    ROW_NUM        = Row[\"row_num\"]\n",
    "    High           = Row[\"high\"]\n",
    "    Low            = Row[\"low\"]\n",
    "    Close          = Row[\"close\"]\n",
    "    # ..........................................\n",
    "    if (Count == Total or Count % 100 == 0):\n",
    "        sys.stdout.write(f\"\"\"\\r[DEBUG] PROCESSING: {OBJECT_Python_3_Text_Progress_Bar.Double_Line_Arrow(Count = Count, Total = Total)}\"\"\")\n",
    "        sys.stdout.flush()\n",
    "    # ..........................................\n",
    "    EMA12       = OBJECT_Python_3_Finance_Indicator_EMA12.EMA(ROW_NUM = ROW_NUM, Period = 12, Close = Close)\n",
    "    EMA26       = OBJECT_Python_3_Finance_Indicator_EMA26.EMA(ROW_NUM = ROW_NUM, Period = 26, Close = Close)\n",
    "    MACD_DIF    = OBJECT_Python_3_Finance_Indicator_MACD.MACD_DIF(EMA12 = EMA12, EMA26 = EMA26)\n",
    "    MACD_DEA    = OBJECT_Python_3_Finance_Indicator_MACD.MACD_DEA(ROW_NUM = ROW_NUM, MACD_DIF = MACD_DIF)\n",
    "    MACD_STICK  = OBJECT_Python_3_Finance_Indicator_MACD.MACD_STICK(MACD_DIF = MACD_DIF, MACD_DEA = MACD_DEA)\n",
    "    KDJ_K       = OBJECT_Python_3_Finance_Indicator_KDJ.KDJ_K(ROW_NUM = ROW_NUM, RSV_Prd = 9, K_Prd = 3, High = High, Low = Low, Close = Close)\n",
    "    KDJ_D       = OBJECT_Python_3_Finance_Indicator_KDJ.KDJ_D(ROW_NUM = ROW_NUM, RSV_Prd = 9, D_Prd = 3, K_Val = KDJ_K)\n",
    "    KDJ_J       = OBJECT_Python_3_Finance_Indicator_KDJ.KDJ_J(K_Val = KDJ_K, D_Val = KDJ_D)\n",
    "    ETG_TRS     = OBJECT_Python_3_Finance_Entanglement_Theory.Top_Reversal_Shape(ROW_NUM = ROW_NUM, Input_UpperEdge = High, Input_LowerEdge = Low)\n",
    "    ETG_BRS     = OBJECT_Python_3_Finance_Entanglement_Theory.Bottom_Reversal_Shape(ROW_NUM = ROW_NUM, Input_UpperEdge = High, Input_LowerEdge = Low)\n",
    "    ETG_T_GROUP = OBJECT_Python_3_Finance_Entanglement_Theory.Top_Reversal_Shape_s_Group_Top(ROW_NUM = ROW_NUM, Input_UpperEdge = High, Input_LowerEdge = Low)\n",
    "    ETG_B_GROUP = OBJECT_Python_3_Finance_Entanglement_Theory.Bottom_Reversal_Shape_s_Group_Bottom(ROW_NUM = ROW_NUM, Input_UpperEdge = High, Input_LowerEdge = Low)\n",
    "    # ..........................................\n",
    "    JSON_Records_Stocks_Daily_Indicator.append({\n",
    "        \"id\":          ID,\n",
    "        \"sma5\":        OBJECT_Python_3_Finance_Indicator_SMA5.SMA(ROW_NUM = ROW_NUM, Period = 5, Close = Close),\n",
    "        \"sma10\":       OBJECT_Python_3_Finance_Indicator_SMA10.SMA(ROW_NUM = ROW_NUM, Period = 10, Close = Close),\n",
    "        \"ema12\":       EMA12,\n",
    "        \"ema26\":       EMA26,\n",
    "        \"macd_dif\":    MACD_DIF,\n",
    "        \"macd_dea\":    MACD_DEA,\n",
    "        \"macd_stick\":  MACD_STICK,\n",
    "        \"kdj_k\":       KDJ_K,\n",
    "        \"kdj_d\":       KDJ_D,\n",
    "        \"kdj_j\":       KDJ_J,\n",
    "        \"etg_trs\":     ETG_TRS,\n",
    "        \"etg_brs\":     ETG_BRS,\n",
    "        \"etg_t_group\": ETG_T_GROUP,\n",
    "        \"etg_b_group\": ETG_B_GROUP\n",
    "    })\n",
    "    # ..........................................\n",
    "    Count = Count + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3c080518-faac-4170-bfa2-3a97340411f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>sma5</th>\n",
       "      <th>sma10</th>\n",
       "      <th>ema12</th>\n",
       "      <th>ema26</th>\n",
       "      <th>macd_dif</th>\n",
       "      <th>macd_dea</th>\n",
       "      <th>macd_stick</th>\n",
       "      <th>kdj_k</th>\n",
       "      <th>kdj_d</th>\n",
       "      <th>kdj_j</th>\n",
       "      <th>etg_trs</th>\n",
       "      <th>etg_brs</th>\n",
       "      <th>etg_t_group</th>\n",
       "      <th>etg_b_group</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>744512</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11.4300</td>\n",
       "      <td>11.4300</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>749881</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11.4223</td>\n",
       "      <td>11.4263</td>\n",
       "      <td>-0.0040</td>\n",
       "      <td>-0.0008</td>\n",
       "      <td>-0.0064</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>755253</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11.4250</td>\n",
       "      <td>11.4273</td>\n",
       "      <td>-0.0023</td>\n",
       "      <td>-0.0011</td>\n",
       "      <td>-0.0024</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>760623</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11.4381</td>\n",
       "      <td>11.4334</td>\n",
       "      <td>0.0047</td>\n",
       "      <td>0.0001</td>\n",
       "      <td>0.0092</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>765996</td>\n",
       "      <td>11.452</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11.4476</td>\n",
       "      <td>11.4384</td>\n",
       "      <td>0.0092</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0146</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>50.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063607</th>\n",
       "      <td>1041885</td>\n",
       "      <td>21.188</td>\n",
       "      <td>21.236</td>\n",
       "      <td>21.3196</td>\n",
       "      <td>21.3406</td>\n",
       "      <td>-0.0210</td>\n",
       "      <td>-0.0600</td>\n",
       "      <td>0.0780</td>\n",
       "      <td>58.9734</td>\n",
       "      <td>58.3653</td>\n",
       "      <td>60.1896</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063608</th>\n",
       "      <td>1047317</td>\n",
       "      <td>21.572</td>\n",
       "      <td>21.282</td>\n",
       "      <td>21.4428</td>\n",
       "      <td>21.3984</td>\n",
       "      <td>0.0444</td>\n",
       "      <td>-0.0391</td>\n",
       "      <td>0.1670</td>\n",
       "      <td>63.1962</td>\n",
       "      <td>59.9756</td>\n",
       "      <td>69.6374</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063609</th>\n",
       "      <td>1052748</td>\n",
       "      <td>21.818</td>\n",
       "      <td>21.344</td>\n",
       "      <td>21.4946</td>\n",
       "      <td>21.4266</td>\n",
       "      <td>0.0680</td>\n",
       "      <td>-0.0177</td>\n",
       "      <td>0.1714</td>\n",
       "      <td>61.7825</td>\n",
       "      <td>60.5779</td>\n",
       "      <td>64.1917</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063610</th>\n",
       "      <td>1058180</td>\n",
       "      <td>21.802</td>\n",
       "      <td>21.371</td>\n",
       "      <td>21.5001</td>\n",
       "      <td>21.4343</td>\n",
       "      <td>0.0658</td>\n",
       "      <td>-0.0010</td>\n",
       "      <td>0.1336</td>\n",
       "      <td>57.7306</td>\n",
       "      <td>59.6288</td>\n",
       "      <td>53.9342</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063611</th>\n",
       "      <td>1063612</td>\n",
       "      <td>21.858</td>\n",
       "      <td>21.472</td>\n",
       "      <td>21.6478</td>\n",
       "      <td>21.5103</td>\n",
       "      <td>0.1375</td>\n",
       "      <td>0.0267</td>\n",
       "      <td>0.2216</td>\n",
       "      <td>66.5966</td>\n",
       "      <td>61.9514</td>\n",
       "      <td>75.8870</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1063612 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              id    sma5   sma10    ema12    ema26  macd_dif  macd_dea  \\\n",
       "0         744512     NaN     NaN  11.4300  11.4300    0.0000    0.0000   \n",
       "1         749881     NaN     NaN  11.4223  11.4263   -0.0040   -0.0008   \n",
       "2         755253     NaN     NaN  11.4250  11.4273   -0.0023   -0.0011   \n",
       "3         760623     NaN     NaN  11.4381  11.4334    0.0047    0.0001   \n",
       "4         765996  11.452     NaN  11.4476  11.4384    0.0092    0.0019   \n",
       "...          ...     ...     ...      ...      ...       ...       ...   \n",
       "1063607  1041885  21.188  21.236  21.3196  21.3406   -0.0210   -0.0600   \n",
       "1063608  1047317  21.572  21.282  21.4428  21.3984    0.0444   -0.0391   \n",
       "1063609  1052748  21.818  21.344  21.4946  21.4266    0.0680   -0.0177   \n",
       "1063610  1058180  21.802  21.371  21.5001  21.4343    0.0658   -0.0010   \n",
       "1063611  1063612  21.858  21.472  21.6478  21.5103    0.1375    0.0267   \n",
       "\n",
       "         macd_stick    kdj_k    kdj_d    kdj_j  etg_trs  etg_brs  etg_t_group  \\\n",
       "0            0.0000  50.0000  50.0000  50.0000      0.0      0.0          0.0   \n",
       "1           -0.0064  50.0000  50.0000  50.0000      0.0      0.0          0.0   \n",
       "2           -0.0024  50.0000  50.0000  50.0000      0.0      0.0          0.0   \n",
       "3            0.0092  50.0000  50.0000  50.0000      0.0      0.0          1.0   \n",
       "4            0.0146  50.0000  50.0000  50.0000      0.0      1.0          1.0   \n",
       "...             ...      ...      ...      ...      ...      ...          ...   \n",
       "1063607      0.0780  58.9734  58.3653  60.1896      0.0      0.0          1.0   \n",
       "1063608      0.1670  63.1962  59.9756  69.6374      0.0      0.0          1.0   \n",
       "1063609      0.1714  61.7825  60.5779  64.1917      0.0      0.0          1.0   \n",
       "1063610      0.1336  57.7306  59.6288  53.9342      0.0      0.0          1.0   \n",
       "1063611      0.2216  66.5966  61.9514  75.8870      0.0      0.0          1.0   \n",
       "\n",
       "         etg_b_group  \n",
       "0                0.0  \n",
       "1                1.0  \n",
       "2                1.0  \n",
       "3                1.0  \n",
       "4                0.0  \n",
       "...              ...  \n",
       "1063607          1.0  \n",
       "1063608          1.0  \n",
       "1063609          1.0  \n",
       "1063610          1.0  \n",
       "1063611          1.0  \n",
       "\n",
       "[1063612 rows x 15 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DataFrame_Stocks_Daily_Indicator = pandas.DataFrame(JSON_Records_Stocks_Daily_Indicator)\n",
    "DataFrame_Stocks_Daily_Indicator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a63b3a67-9ca3-41c6-9327-7c50731fd639",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1063612"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "OBJECT_Python_3_SQLAlchemy_2_SQLite_3.TRUNCATE_TABLE(DB_TABLE_DAILY_DATA_INDICATOR)\n",
    "OBJECT_Python_3_SQLAlchemy_2_SQLite_3.APPEND_DataFrame(DataFrame_Stocks_Daily_Indicator, DB_TABLE_DAILY_DATA_INDICATOR)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3cc14cf-33c3-49ed-afc2-6acea70c0fd6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d8c872d8-a20c-48f3-9fdc-0abda0bc290c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = OBJECT_Python_3_Finance_DataFrame_Preprocessing.Before_Converting_Daily_to_Weekly(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a97ccd25-a4e8-410c-8ba1-5c14f283ba9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[DEBUG] PROCESSING: [====================>] Pct: 1.00 | 1063612/1063612"
     ]
    }
   ],
   "source": [
    "JSON_Records_Stocks_Daily_to_Weekly:list = []\n",
    "# ..............................................\n",
    "Total = df[\"id\"].count()\n",
    "Count = 1\n",
    "# ..............................................\n",
    "for Idx, Row in df.iterrows():\n",
    "    Daily_ID      = Row[\"id\"]\n",
    "    ROW_NUM       = Row[\"row_num\"]\n",
    "    Daily_Time    = Row[\"time\"]\n",
    "    Week_Num      = Row[\"week_num\"]\n",
    "    ISO_8601_Week = Row[\"iso_8601_week\"]\n",
    "    Code          = Row[\"code\"]\n",
    "    Daily_Open    = Row[\"open\"]\n",
    "    Daily_High    = Row[\"high\"]\n",
    "    Daily_Low     = Row[\"low\"]\n",
    "    Daily_Close   = Row[\"close\"]\n",
    "    Daily_Change  = Row[\"change\"]\n",
    "    Daily_Volume  = Row[\"volume\"]\n",
    "    # ..........................................\n",
    "    if (Count == Total or Count % 100 == 0):\n",
    "        sys.stdout.write(f\"\"\"\\r[DEBUG] PROCESSING: {OBJECT_Python_3_Text_Progress_Bar.Double_Line_Arrow(Count = Count, Total = Total)}\"\"\")\n",
    "        sys.stdout.flush()\n",
    "    # ..........................................\n",
    "    Weekly_Time   = OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly.WK_Time(ROW_NUM = ROW_NUM, DY_Time = Daily_Time)\n",
    "    Weekly_Open   = OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly.WK_Open(ROW_NUM = ROW_NUM, DY_Open = Daily_Open)\n",
    "    Weekly_High   = OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly.WK_High(ROW_NUM = ROW_NUM, DY_High = Daily_High)\n",
    "    Weekly_Low    = OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly.WK_Low(ROW_NUM = ROW_NUM, DY_Low = Daily_Low)\n",
    "    Weekly_Close  = OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly.WK_Close(ROW_NUM = ROW_NUM, DY_Close = Daily_Close)\n",
    "    Weekly_Change = OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly.WK_Change(ROW_NUM = ROW_NUM, DY_Change = Daily_Change)\n",
    "    Weekly_Volume = OBJECT_Python_3_Finance_Data_Conv_Daily_to_Weekly.WK_Volume(ROW_NUM = ROW_NUM, DY_Volume = Daily_Volume)\n",
    "    # ..........................................\n",
    "    JSON_Records_Stocks_Daily_to_Weekly.append({\n",
    "        \"id\":            ID,\n",
    "        \"row_num\":       ROW_NUM,\n",
    "        \"weekly_time\":   Weekly_Time,\n",
    "        \"week_num\":      Week_Num,\n",
    "        \"iso_8601_week\": ISO_8601_Week,\n",
    "        \"code\":          Code,\n",
    "        \"weekly_open\":   Weekly_Open,\n",
    "        \"weekly_high\":   Weekly_High,\n",
    "        \"weekly_low\":    Weekly_Low,\n",
    "        \"weekly_close\":  Weekly_Close,\n",
    "        \"weekly_change\": Weekly_Change,\n",
    "        \"weekly_volume\": Weekly_Volume\n",
    "    })\n",
    "    # ..........................................\n",
    "    Count = Count + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "166efb16-d6c0-4a3f-8535-2b28b9729c49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>row_num</th>\n",
       "      <th>weekly_time</th>\n",
       "      <th>week_num</th>\n",
       "      <th>iso_8601_week</th>\n",
       "      <th>code</th>\n",
       "      <th>weekly_open</th>\n",
       "      <th>weekly_high</th>\n",
       "      <th>weekly_low</th>\n",
       "      <th>weekly_close</th>\n",
       "      <th>weekly_change</th>\n",
       "      <th>weekly_volume</th>\n",
       "      <th>cum_max</th>\n",
       "      <th>source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1063611</th>\n",
       "      <td>1063612</td>\n",
       "      <td>3</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>43</td>\n",
       "      <td>2025-W43</td>\n",
       "      <td>920992.BJ</td>\n",
       "      <td>22.20</td>\n",
       "      <td>22.46</td>\n",
       "      <td>21.00</td>\n",
       "      <td>22.46</td>\n",
       "      <td>0.34</td>\n",
       "      <td>51410.27</td>\n",
       "      <td>3</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>675151</th>\n",
       "      <td>1063612</td>\n",
       "      <td>3</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>43</td>\n",
       "      <td>2025-W43</td>\n",
       "      <td>600730.SH</td>\n",
       "      <td>9.98</td>\n",
       "      <td>10.37</td>\n",
       "      <td>9.41</td>\n",
       "      <td>10.14</td>\n",
       "      <td>0.12</td>\n",
       "      <td>772083.49</td>\n",
       "      <td>3</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>969593</th>\n",
       "      <td>1063612</td>\n",
       "      <td>3</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>43</td>\n",
       "      <td>2025-W43</td>\n",
       "      <td>688432.SH</td>\n",
       "      <td>12.92</td>\n",
       "      <td>13.29</td>\n",
       "      <td>12.70</td>\n",
       "      <td>12.81</td>\n",
       "      <td>0.14</td>\n",
       "      <td>348719.43</td>\n",
       "      <td>3</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>674560</th>\n",
       "      <td>1063612</td>\n",
       "      <td>3</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>43</td>\n",
       "      <td>2025-W43</td>\n",
       "      <td>600727.SH</td>\n",
       "      <td>7.55</td>\n",
       "      <td>7.61</td>\n",
       "      <td>7.45</td>\n",
       "      <td>7.54</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>145999.00</td>\n",
       "      <td>3</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1062077</th>\n",
       "      <td>1063612</td>\n",
       "      <td>3</td>\n",
       "      <td>2025-10-29</td>\n",
       "      <td>43</td>\n",
       "      <td>2025-W43</td>\n",
       "      <td>920689.BJ</td>\n",
       "      <td>36.44</td>\n",
       "      <td>38.19</td>\n",
       "      <td>36.01</td>\n",
       "      <td>38.09</td>\n",
       "      <td>1.28</td>\n",
       "      <td>54159.90</td>\n",
       "      <td>3</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>481526</th>\n",
       "      <td>1063612</td>\n",
       "      <td>2</td>\n",
       "      <td>2025-01-03</td>\n",
       "      <td>00</td>\n",
       "      <td>2025-W00</td>\n",
       "      <td>301024.SZ</td>\n",
       "      <td>23.58</td>\n",
       "      <td>24.67</td>\n",
       "      <td>21.62</td>\n",
       "      <td>21.81</td>\n",
       "      <td>-1.99</td>\n",
       "      <td>29013.50</td>\n",
       "      <td>2</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>690819</th>\n",
       "      <td>1063612</td>\n",
       "      <td>2</td>\n",
       "      <td>2025-01-03</td>\n",
       "      <td>00</td>\n",
       "      <td>2025-W00</td>\n",
       "      <td>600825.SH</td>\n",
       "      <td>6.50</td>\n",
       "      <td>6.67</td>\n",
       "      <td>5.94</td>\n",
       "      <td>5.98</td>\n",
       "      <td>-0.57</td>\n",
       "      <td>570170.21</td>\n",
       "      <td>2</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>291227</th>\n",
       "      <td>1063612</td>\n",
       "      <td>2</td>\n",
       "      <td>2025-01-03</td>\n",
       "      <td>00</td>\n",
       "      <td>2025-W00</td>\n",
       "      <td>003042.SZ</td>\n",
       "      <td>14.18</td>\n",
       "      <td>14.65</td>\n",
       "      <td>13.28</td>\n",
       "      <td>13.38</td>\n",
       "      <td>-0.87</td>\n",
       "      <td>78698.00</td>\n",
       "      <td>2</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998064</th>\n",
       "      <td>1063612</td>\n",
       "      <td>2</td>\n",
       "      <td>2025-01-03</td>\n",
       "      <td>00</td>\n",
       "      <td>2025-W00</td>\n",
       "      <td>688655.SH</td>\n",
       "      <td>10.74</td>\n",
       "      <td>10.93</td>\n",
       "      <td>9.52</td>\n",
       "      <td>9.56</td>\n",
       "      <td>-1.22</td>\n",
       "      <td>52158.88</td>\n",
       "      <td>2</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>556815</th>\n",
       "      <td>1063612</td>\n",
       "      <td>2</td>\n",
       "      <td>2025-01-03</td>\n",
       "      <td>00</td>\n",
       "      <td>2025-W00</td>\n",
       "      <td>301587.SZ</td>\n",
       "      <td>23.49</td>\n",
       "      <td>23.76</td>\n",
       "      <td>21.64</td>\n",
       "      <td>21.65</td>\n",
       "      <td>-1.85</td>\n",
       "      <td>31120.75</td>\n",
       "      <td>2</td>\n",
       "      <td>converting</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>237169 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              id  row_num weekly_time week_num iso_8601_week       code  \\\n",
       "1063611  1063612        3  2025-10-29       43      2025-W43  920992.BJ   \n",
       "675151   1063612        3  2025-10-29       43      2025-W43  600730.SH   \n",
       "969593   1063612        3  2025-10-29       43      2025-W43  688432.SH   \n",
       "674560   1063612        3  2025-10-29       43      2025-W43  600727.SH   \n",
       "1062077  1063612        3  2025-10-29       43      2025-W43  920689.BJ   \n",
       "...          ...      ...         ...      ...           ...        ...   \n",
       "481526   1063612        2  2025-01-03       00      2025-W00  301024.SZ   \n",
       "690819   1063612        2  2025-01-03       00      2025-W00  600825.SH   \n",
       "291227   1063612        2  2025-01-03       00      2025-W00  003042.SZ   \n",
       "998064   1063612        2  2025-01-03       00      2025-W00  688655.SH   \n",
       "556815   1063612        2  2025-01-03       00      2025-W00  301587.SZ   \n",
       "\n",
       "         weekly_open  weekly_high  weekly_low  weekly_close  weekly_change  \\\n",
       "1063611        22.20        22.46       21.00         22.46           0.34   \n",
       "675151          9.98        10.37        9.41         10.14           0.12   \n",
       "969593         12.92        13.29       12.70         12.81           0.14   \n",
       "674560          7.55         7.61        7.45          7.54          -0.01   \n",
       "1062077        36.44        38.19       36.01         38.09           1.28   \n",
       "...              ...          ...         ...           ...            ...   \n",
       "481526         23.58        24.67       21.62         21.81          -1.99   \n",
       "690819          6.50         6.67        5.94          5.98          -0.57   \n",
       "291227         14.18        14.65       13.28         13.38          -0.87   \n",
       "998064         10.74        10.93        9.52          9.56          -1.22   \n",
       "556815         23.49        23.76       21.64         21.65          -1.85   \n",
       "\n",
       "         weekly_volume  cum_max      source  \n",
       "1063611       51410.27        3  converting  \n",
       "675151       772083.49        3  converting  \n",
       "969593       348719.43        3  converting  \n",
       "674560       145999.00        3  converting  \n",
       "1062077       54159.90        3  converting  \n",
       "...                ...      ...         ...  \n",
       "481526        29013.50        2  converting  \n",
       "690819       570170.21        2  converting  \n",
       "291227        78698.00        2  converting  \n",
       "998064        52158.88        2  converting  \n",
       "556815        31120.75        2  converting  \n",
       "\n",
       "[237169 rows x 14 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DataFrame_Stocks_Daily_to_Weekly = pandas.DataFrame(JSON_Records_Stocks_Daily_to_Weekly)\n",
    "# ..................................................\n",
    "DataFrame_Stocks_Daily_to_Weekly = DataFrame_Stocks_Daily_to_Weekly.sort_values(\"weekly_time\", ascending = False)\n",
    "# ..................................................\n",
    "DataFrame_Stocks_Daily_to_Weekly[\"cum_max\"] = \\\n",
    "DataFrame_Stocks_Daily_to_Weekly[[\"iso_8601_week\", \"row_num\"]].groupby(\"iso_8601_week\", as_index = False).cummax()[\"row_num\"]\n",
    "# ..................................................\n",
    "DataFrame_Stocks_Daily_to_Weekly = \\\n",
    "DataFrame_Stocks_Daily_to_Weekly[DataFrame_Stocks_Daily_to_Weekly[\"row_num\"] == DataFrame_Stocks_Daily_to_Weekly[\"cum_max\"]]\n",
    "# ..................................................\n",
    "DataFrame_Stocks_Daily_to_Weekly[\"source\"] = \"converting\"\n",
    "DataFrame_Stocks_Daily_to_Weekly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5b95a9c6-0edd-42b7-8d05-fb7dd045b78e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "237169"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DataFrame_Stocks_Daily_to_Weekly = DataFrame_Stocks_Daily_to_Weekly.drop([\"id\", \"iso_8601_week\", \"row_num\", \"cum_max\"], axis = 1)\n",
    "DataFrame_Stocks_Daily_to_Weekly = DataFrame_Stocks_Daily_to_Weekly.rename(columns = {\n",
    "    \"weekly_time\":   \"time\",\n",
    "    \"weekly_open\":   \"open\",\n",
    "    \"weekly_high\":   \"high\",\n",
    "    \"weekly_low\":    \"low\",\n",
    "    \"weekly_close\":  \"close\",\n",
    "    \"weekly_change\": \"change\",\n",
    "    \"weekly_volume\": \"volume\"\n",
    "})\n",
    "OBJECT_Python_3_SQLAlchemy_2_SQLite_3.TRUNCATE_TABLE(DB_TABLE_WEEKLY_DATA)\n",
    "OBJECT_Python_3_SQLAlchemy_2_SQLite_3.APPEND_DataFrame(DataFrame_Stocks_Daily_to_Weekly, DB_TABLE_WEEKLY_DATA)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea9a319d-56af-4b1b-b011-76eab54d6599",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
